define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/score/index' + location.search,
                    add_url: 'user/score/add',
                    edit_url: 'user/score/edit',
                    del_url: 'user/score/del',
                    multi_url: 'user/score/multi',
                    table: 'user',
                }
            });

            var table = $("#table");
            var  stvisible = '=';
            var  stvisible2 = false;
            if(Config.org_cate_id > 0){
                stvisible = false;
                stvisible2 = '=';
            }
            table.on('post-common-search.bs.table', function (event, table) {
                $(".commonsearch-table").find('.btn-success').html('搜索');
                $(".commonsearch-table").find('.btn-default').html('刷新');
                $(".columns-right").hide();
                $('.form-commonsearch').attr('autocomplete', 'off');
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'sort', title: __('序号'),operate:false},
                        {field: 'user.number_id', title: __('学生学号'),operate:false},
                        {field: 'user.nickname', title: __('学生姓名'),operate:false},
                        {field: 'username', title: __('家长登录名'),operate:false},
                        {field: 'nickname', title: __('家长姓名'),operate:false},
                        {field: 'score', title: __('Score'),operate:false},
                        {field: 'timelong', title: __('Timelong'),operate:false},
                        {field: 'sort', title: __('积分排名'),operate:false},
                        {
                            field: 'orgcateid',
                            title: __('单位'),
                            visible: false,
                            operate:stvisible,
                            align: 'left',
                            // operate:'like',
                            searchList: $.getJSON('usechart/searchlist')
                        },
                        {
                            field: 'g.group',
                            title: __('年级'),
                            visible: false,
                            align: 'left',
                            // operate:'like',
                            searchList: $.getJSON('user/score/searchgroup')
                        },
                        {
                            field: 't.org_grade_id',
                            title: __('班级编号'),
                            visible: false,
                            operate:stvisible2,
                            align: 'left',
                            // operate:'like',
                            searchList: $.getJSON('user/score/searchlist')
                        }
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: true,
                search:false,
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ["100%","100%"]);
                    $(".columns-right").hide();
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});